<?php
/**
 * @package    JWPBlog
 * @author David Neimeyer davidneimeyer@gmail.com
 * @link http://indie-bookstore.googlecode.com/
 * @license    GNU/GPL
 *
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport( 'joomla.application.component.view');

/**
 * HTML View for the bookstore component
 *
 * this is a basic console (grid) for access
 *  to the sub components
 */

class JWPBlogViewEdit extends JView
{
	function display($tpl = NULL){
		var_dump('editview');
		$this->old_edit_php($tpl);
		//parent::display($tpl);
	}

	function old_edit_php(){
		var_dump('old_edit_php');
		$reg = JRegistry::getInstance('mojo');//1.5
		$admin_path = $reg->getValue('config.admin_path');//1.5
		require_once($admin_path.DS.'admin.php');
		
		$model = $this->getModel();
		global $my;
		$my = $reg->getValue('users.my',$my);

		$title = JText::_('Posts');
		//$title = __('Posts');
		
		$parent_file = 'edit.php';
		$reg->setValue('parent.file','edit.php');
		require_once($admin_path.DS.'admin-header.php');

		JRequest::setVar('m',JRequest::getInt('m'));
		//$_GET['m'] = (int) $_GET['m'];
		
		$drafts = $model->get_users_drafts( $my->id );
		$other_drafts = $model->get_others_drafts( $my->id );
		//$drafts = get_users_drafts( $my->id );
		//$other_drafts = get_others_drafts( $my->id);
		
		$what_to_show = 'posts';
		$posts_per_page = 15;
		$posts_per_archive_page = -1;

		$model->wp();
		//wp();
		
		$sql = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM ".$model->getData('posts')." WHERE post_date != '0000-00-00 00:00:00' ORDER BY post_date DESC";
		$arc_result = $model->get_results($sql);
		//$arc_result = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_date != '0000-00-00 00:00:00' ORDER BY post_date DESC");
		
		// define the columns to display, the syntax is 'internal name' => 'display name'
		$posts_columns = array(
 						'id'         => JText::_('ID'),
  						'date'       => JText::_('When'),
						'title'      => JText::_('Title'),
						'categories' => JText::_('Categories'),
						'comments'   => JText::_('Comments'),
						'author'     => JText::_('Author')
						);
		$posts_columns = $model->apply_filters('manage_posts_columns', $posts_columns);
		//$posts_columns = apply_filters('manage_posts_columns', $posts_columns);
		// you can not edit these at the moment
		$posts_columns['control_view']   = '';
		$posts_columns['control_edit']   = '';
		$posts_columns['control_delete'] = '';
		
		$posts = $model->getPosts();
		$model->preparePosts($posts);
		
		/*$posts_columns = array(
 						'id'         => __('ID'),
  						'date'       => __('When'),
						'title'      => __('Title'),
						'categories' => __('Categories'),
						'comments'   => __('Comments'),
						'author'     => __('Author')
						);
						*/
		
		/////////////////  assignments  ///////////////////
		$this->assignRef('title',$title);
		$this->assignRef('drafts',$drafts);
		$this->assignRef('other_drafts',$other_drafts);
		$this->assignRef('arc_result',$arc_result);
		$this->assignRef('posts_columns',$posts_columns);
		$this->assignRef('posts',$posts);
		
		///////////////////////////////////////////////////
		//$this->display();
		parent::display($tpl);
		

	
	

	?>

<div id="ajax-response"></div>

<div class="navigation">
<div class="alignleft"><?php next_posts_link(__('&laquo; Previous Entries')) ?></div>
<div class="alignright"><?php previous_posts_link(__('Next Entries &raquo;')) ?></div>
</div>

	<?php
	if ( 1 == count($posts) ) {

		$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = $id AND comment_approved != 'spam' ORDER BY comment_date");
		if ($comments) {
			?>
<h3><?php _e('Comments') ?></h3>
<ol id="comments">
<?php
foreach ($comments as $comment) {
	$comment_status = wp_get_comment_status($comment->comment_ID);
	?>

	<li
	<?php if ("unapproved" == $comment_status) echo "class='unapproved'"; ?>>
		<?php comment_date('Y-n-j') ?> @ <?php comment_time('g:m:s a') ?> <?php
		if ( current_user_can('edit_post', $post->ID) ) {
			echo "[ <a href=\"post.php?action=editcomment&amp;comment=".$comment->comment_ID."\">" .  __('Edit') . "</a>";
			echo " - <a href=\"post.php?action=deletecomment&amp;p=".$post->ID."&amp;comment=".$comment->comment_ID."\" onclick=\"return confirm('" . sprintf(__("You are about to delete this comment by &quot;%s&quot;.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), $comment->comment_author) . "');\">" . __('Delete') . "</a> ";
			if ( ('none' != $comment_status) && ( current_user_can('moderate_comments') ) ) {
				if ('approved' == wp_get_comment_status($comment->comment_ID)) {
					echo " - <a href=\"post.php?action=unapprovecomment&amp;p=".$post->ID."&amp;comment=".$comment->comment_ID."\">" . __('Unapprove') . "</a> ";
				} else {
					echo " - <a href=\"post.php?action=approvecomment&amp;p=".$post->ID."&amp;comment=".$comment->comment_ID."\">" . __('Approve') . "</a> ";
				}
			}
			echo "]";
		} // end if any comments to show
		?> <br />
	<strong> <?php comment_author() ?> ( <?php comment_author_email_link() ?>
	/ <?php comment_author_url_link() ?> )</strong> (IP: <?php comment_author_IP() ?>
	) <?php comment_text() ?></li>
	<!-- /comment -->
	<?php //end of the loop, don't delete
} // end foreach
echo '</ol>';
		}//end if comments
		?>
		<?php } ?>

</div>
		<?php
		include($admin_path.DS.'admin-footer.php');


	}
}
?>